import 'package:flutter/material.dart';
import 'package:wanchong/app/home/me.dart';
import 'package:wanchong/app/home/video.dart';
import 'package:wanchong/app/knowledge/home.dart';
import 'package:wanchong/app/store/home.dart';
import 'package:wanchong/app/user/choose.dart';
import 'package:wanchong/conf.dart';
import 'package:flutter_custom_bottom_tab_bar/tabbar.dart';
import 'package:flutter_custom_bottom_tab_bar/eachtab.dart';
import 'mecollect/vid.dart';
import 'home/know.dart';
class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home>with SingleTickerProviderStateMixin {
  int _current = 0;
  TabController _tabController;
  List<Widget> _pages = [
    Video(),
    //Vid(),
    StroeHome(),
    Choose(),
    Konw(),
    Me()
  ];
  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: titles.length, vsync: this, initialIndex: _current);
    _tabController.addListener(() {
      setState(() => _current = _tabController.index);
      // print("liucheng-> ${_tabController.indexIsChanging}");
    });
  }

  var titles = ["首页","门店","","知识","我的"];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: _bottom(),
      body: TabBarView(
        physics: NeverScrollableScrollPhysics(),
        controller: _tabController,
        children: _pages,
      ),
    );
  }
  Widget _bottom() {
    return Container(
      color: Color.fromRGBO(26, 27, 30, 1),

      height: Bottom.bottomHeight,
      child: Column(
        children: <Widget>[
          Divider(height: 2.0,),
          new TabBar(
            isScrollable: false,
            controller: _tabController,
            indicatorColor: Colors.transparent,
            labelColor: Color(Bottom.pressColor),
            labelPadding: EdgeInsets.all(0),
            unselectedLabelColor: Color(Bottom.normalColor),
            tabs: <Widget>[
              _bottomItem(0,'assets/bottom/navigation_icon_home_b.png','assets/bottom/navigation_icon_home_a.png'),
              _bottomItem(1,'assets/bottom/navigation_icon_shop_b.png','assets/bottom/navigation_icon_shop_a.png'),
              EachTab(
                  padding: EdgeInsets.all(0),
                  icon: Image.asset(
                    'assets/bottom/navigation_icon_function.png',
                    width: 67,
                    height: 40,
                  ),
                  iconPadding: EdgeInsets.fromLTRB(0, 0, 0, 2)),
              _bottomItem(3,'assets/bottom/navigation_icon_intellectual_b.png','assets/bottom/navigation_icon_intellectual_a.png'),
              _bottomItem(4,'assets/bottom/navigation_icon_center_b.png','assets/bottom/navigation_icon_center_a.png'),
            ],
          )
        ],
      ),
    );
  }
  Widget _bottomItem(int index,String normal,String press) {
    return EachTab(
      height: 50.0,
      padding: EdgeInsets.all(0),
      icon: _current == index
          ? Image.asset(normal,width: 18.0,height: 20.0,)
          : Image.asset(press,width: 18.0,height: 20.0,),
      text: titles[index],
      iconPadding: EdgeInsets.fromLTRB(0, 0, 0, 2),
      textStyle: TextStyle(fontSize: 12.0),
    );
  }
}
